home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 8.4 KB | 335 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: BmpPart.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Henri Lamiraux
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef BMPPART_H
- #include "BmpPart.h"
- #endif
-
- #ifndef BMPFRAME_H
- #include "BmpFrame.h"
- #endif
-
- #ifndef BMPFACET_H
- #include "BmpFacet.h"
- #endif
-
- #ifndef BMPSEL_H
- #include "BmpSel.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- // ----- Graphic Includes -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWPICSHP_H
- #include "FWPicShp.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSUSTRM_H
- #include "FWSUStrm.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _XMPSESSN_
- #include <XMPSessM.h>
- #endif
-
- #ifndef _ARBITRAT_
- #include <Arbitrat.h>
- #endif
-
- #ifndef _DISPTCH_
- #include <Disptch.h>
- #endif
-
- #ifndef _STORAGEU_
- #include <StorageU.h>
- #endif
-
- #ifndef _SHAPE_
- #include <Shape.h>
- #endif
-
- #ifndef _WINDOW_
- #include <Window.h>
- #endif
-
- #ifndef _STDTYPES_
- #include <StdTypes.h>
- #endif
-
- #ifndef _STDPROPS_
- #include <StdProps.h>
- #endif
-
- #ifndef _MENUBAR_
- #include <MenuBar.h>
- #endif
-
- #ifndef _CMDDEFS_
- #include <CmdDefs.h>
- #endif
-
- #ifndef _TRANSLAT_
- #include <Translat.h>
- #endif
-
- #ifndef _XMPSESSN_
- #include <XMPSessM.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
- #include <math routines.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
- #include <QuickDraw.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
- #include <Resources.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__TOOLUTILS__)
- #include <ToolUtils.h>
- #endif
-
- #pragma segment bitmappart
-
- //========================================================================================
- // •• class CBitmapPart
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CBitmapPart::CBitmapPart
- //----------------------------------------------------------------------------------------
-
- CBitmapPart::CBitmapPart() :
- fDisplayMenu(NULL),
- fBitmapSelection(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapPart::~CBitmapPart
- //----------------------------------------------------------------------------------------
-
- CBitmapPart::~CBitmapPart()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapPart::Release
- //----------------------------------------------------------------------------------------
-
- void CBitmapPart::Release()
- {
- FW_CPart::Release();
-
- if (this->GetRefCount() == 1)
- {
- this->GetSession()->GetDispatcher()->UnregisterIdle(this, NULL);
- }
-
- if (GetRefCount() == 0)
- {
- if (fDisplayMenu)
- {
- ::DisposeMenu(fDisplayMenu);
- fDisplayMenu = NULL;
- }
-
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CBitmapPart::Initialize()
- {
- FW_CPart::Initialize();
-
- // ----- Initialize the bitmap shape -----
- {
- FW_CAcquireASLMResourceAccess aq;
- PicHandle picture = ::GetPicture(2128);
- ::DetachResource((Handle)picture);
- FW_CPictShape pictShape(picture);
- fBitmapShape = pictShape;
- }
-
- fDisplayMenu = ::NewMenu(kDisplayMenu,"\pDisplay");
-
- ::AppendMenu(fDisplayMenu,"\pHalf Size");
- ::AppendMenu(fDisplayMenu,"\pReal Size");
- ::AppendMenu(fDisplayMenu,"\pDouble Size");
-
- XMPMenuBar *menuBar = GetMenuBar();
-
- menuBar->AddMenuLast(kDisplayMenu, fDisplayMenu, this);
-
- menuBar->RegisterCommand(cHalfSize, kDisplayMenu, 1);
- menuBar->RegisterCommand(cRealSize, kDisplayMenu, 2);
- menuBar->RegisterCommand(cDoubleSize, kDisplayMenu, 3);
-
- this->GetSession()->GetDispatcher()->RegisterIdle(this, NULL, 15);
- }
-
- //----------------------------------------------------------------------------------------
- // • CBitmapPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- void CBitmapPart::DoAdjustMenus(XMPMenuBar* menuBar)
- {
- FW_CPart::DoAdjustMenus(menuBar);
-
- XMPTranslation *translate = GetSession()->GetTranslation();
- XMPType PICTType = translate->GetISOTypeFromPlatformType('PICT', kXMPPlatformDataType);
-
- menuBar->EnableCommand(kXMPCommandPaste, HasPropertyOnClipboard(kXMPPropContents, kBitmapPartKind) ||
- HasPropertyOnClipboard(kXMPPropContents, PICTType));
- menuBar->EnableCommand(kXMPCommandSelectAll, TRUE);
-
- menuBar->EnableCommand(kXMPCommandClear, FALSE);
- menuBar->EnableCommand(kXMPCommandCut, FALSE);
- menuBar->EnableCommand(kXMPCommandCopy, !fBitmapSelection->IsEmpty());
- menuBar->EnableCommand(kXMPCommandPasteAs, FALSE);
- }
-
- //----------------------------------------------------------------------------------------
- // • CBitmapPart::CalcBitmapRect
- //----------------------------------------------------------------------------------------
-
- void CBitmapPart::CalcBitmapRect(FW_CRect *rect, long zoomFactor) const
- {
- short width, height, rowbytes, pixelSize;
- fBitmapShape->GetBitmapInfo(width, height, rowbytes, pixelSize);
-
- rect->Set(0, 0, ff(width), ff(height));
-
- if (zoomFactor == cHalfSize)
- {
- rect->right /= 2;
- rect->bottom /= 2;
- }
- else if (zoomFactor == cDoubleSize)
- {
- rect->right *= 2;
- rect->bottom *= 2;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapPart::InternalizeContent
- //----------------------------------------------------------------------------------------
-
- void CBitmapPart::InternalizeContent(XMPStorageUnit* storageUnit)
- {
- storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, this->GetContentPropertyValueType(), 0, kXMPPosUndefined);
-
- if (storageUnit->GetSize() != 0)
- {
- FW_CStorageUnitSink sink(storageUnit);
- FW_CReadableStream stream(&sink);
- fBitmapShape->Unflatten(stream);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapPart::ExternalizeContent
- //----------------------------------------------------------------------------------------
-
- void CBitmapPart::ExternalizeContent(XMPStorageUnit* storageUnit)
- {
- storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, this->GetContentPropertyValueType(), 0, kXMPPosUndefined);
- storageUnit->Remove();
- storageUnit->AddValue(this->GetContentPropertyValueType());
-
- FW_CStorageUnitSink sink(storageUnit);
- FW_CWritableStream stream(&sink);
- fBitmapShape->Flatten(stream);
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapPart::GetContentPropertyValueType
- //----------------------------------------------------------------------------------------
-
- XMPValueType CBitmapPart::GetContentPropertyValueType() const
- {
- return kBitmapPartKind;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapPart::SetBitmap
- //----------------------------------------------------------------------------------------
-
- void CBitmapPart::SetBitmap(FW_CBitmapShape bitmapShape)
- {
- fBitmapShape = bitmapShape;
- Changed();
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CBitmapPart::NewFrame(XMPFrame* xmpFrame, XMPTypeToken presentation)
- {
- FW_UNUSED(presentation);
-
- CBitmapFrame *frame = new CBitmapFrame;
- frame->InitBitmapFrame(xmpFrame, this);
- return frame;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapPart::NewSelection
- //----------------------------------------------------------------------------------------
-
- FW_CSelection* CBitmapPart::NewSelection()
- {
- fBitmapSelection = new CBitmapSelection;
- fBitmapSelection->InitBitmapSelection(this);
- return fBitmapSelection;
- }
-
- //----------------------------------------------------------------------------------------
- // • CBitmapPart::DoIdle
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CBitmapPart::DoIdle()
- {
- if (fBitmapSelection != NULL && !fBitmapSelection->IsEmpty())
- fBitmapSelection->MoveAnts();
-
- return FW_CPart::DoIdle();
- }
-
-